﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Wix.Aura.Common;
using System.IO;
using Wix.Aura.Common.CustomTypes;

namespace Wix.Aura.UnitTests.Common {
	[TestFixture]
	public class ProductAttributesSerialization : XmlAssertionBase {

		[SetUp]
		public void SetUp() {
			testProductId = Guid.NewGuid();
			testProductLanguage = Language.Default;
			testProductManufacturer = "Manufacturious";
			testProductName = "Test Product";
			testProductVersion = "9.0.10023.142";
			testProduct = new Product(testProductId, testProductLanguage, testProductManufacturer, testProductName, testProductVersion, new Package(Guid.Empty));

			project = new WixProject(testProduct);
			project.RequiredVersion = new VersionType(3, 5, 2, 7);
		}

		private WixProject project;

		private Product testProduct;
		private Guid testProductId;
		private Language testProductLanguage;
		private string testProductManufacturer;
		private string testProductName;
		private string testProductVersion;

		[Test]
		public void RequiredAttributes() {
			string xml = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Wix requiredversion=""3.5.2.7"" xmlns=""http://schemas.microsoft.com/Wix/2006/wi"">
	<Product Id=""{0}"" Language=""{1}"" Manufacturer=""{2}"" Name=""{3}"" Version=""{4}"">
		<Package Id=""00000000-0000-0000-0000-000000000000"" />
	</Product>
</Wix>", testProductId.ToString().ToUpper(), ((int)testProductLanguage).ToString(), testProductManufacturer, testProductName, testProductVersion);

			Assertion(xml, project);
		}

		[Test]
		public void RequiredAndCodePageAttributes() {
			string xml = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Wix requiredversion=""3.5.2.7"" xmlns=""http://schemas.microsoft.com/Wix/2006/wi"">
	<Product Id=""{0}"" Language=""{1}"" Manufacturer=""{2}"" Name=""{3}"" Version=""{4}"" Codepage=""17"">
		<Package Id=""00000000-0000-0000-0000-000000000000"" />
	</Product>
</Wix>", testProductId.ToString().ToUpper(), ((int)testProductLanguage).ToString(), testProductManufacturer, testProductName, testProductVersion);

			project.Product.CodePage = 17;
			Assertion(xml, project);
		}

		[Test]
		public void RequiredAndUpgradeCodeAttributes() {
			Guid upgrade = Guid.NewGuid();

			string xml = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Wix requiredversion=""3.5.2.7"" xmlns=""http://schemas.microsoft.com/Wix/2006/wi"">
	<Product Id=""{0}"" Language=""{1}"" Manufacturer=""{2}"" Name=""{3}"" Version=""{4}"" UpgradeCode=""{5}"">
		<Package Id=""00000000-0000-0000-0000-000000000000"" />
	</Product>
</Wix>", testProductId.ToString().ToUpper(), ((int)testProductLanguage).ToString(), testProductManufacturer, testProductName, testProductVersion, upgrade.ToString().ToUpper());

			project.Product.UpgradeCode = upgrade;
			Assertion(xml, project);
		}

		[Test]
		public void AllAttributes() {
			Guid upgrade = Guid.NewGuid();
			int codepage = 5;
			string xml = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Wix requiredversion=""3.5.2.7"" xmlns=""http://schemas.microsoft.com/Wix/2006/wi"">
	<Product Id=""{0}"" Language=""{1}"" Manufacturer=""{2}"" Name=""{3}"" Version=""{4}"" Codepage=""{5}"" UpgradeCode=""{6}"">
		<Package Id=""00000000-0000-0000-0000-000000000000"" />
	</Product>
</Wix>", testProductId.ToString().ToUpper(), ((int)testProductLanguage).ToString(), testProductManufacturer, testProductName, testProductVersion,codepage, upgrade.ToString().ToUpper());

			project.Product.UpgradeCode = upgrade;
			project.Product.CodePage = codepage;
			Assertion(xml, project);
		}
	}
}
